using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MaritalStatusPreferenceDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MaritalStatusPreferenceDA()
		{
		}

		public MaritalStatusPreferenceDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MaritalStatusPreference table.
		/// </summary>
		public  int Insert(MaritalStatusPreference maritalStatusPreference)
		{
			ValidationUtility.ValidateArgument("maritalStatusPreference", maritalStatusPreference);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", maritalStatusPreference.TenantID),
				new SqlParameter("@ProfileID", maritalStatusPreference.ProfileID),
				new SqlParameter("@MartialStatusID", maritalStatusPreference.MartialStatusID)
			};

			maritalStatusPreference.PreferenceID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MaritalStatusPreferenceInsert", parameters));
			return maritalStatusPreference.PreferenceID;
		}

		/// <summary>
		/// Deletes a record from the MaritalStatusPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MaritalStatusPreferenceDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MaritalStatusPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MaritalStatusPreferenceDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects all records from the MaritalStatusPreference table.
		/// </summary>
		public  List<MaritalStatusPreference> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MaritalStatusPreferenceSelectAll", parameters))
			{
				List<MaritalStatusPreference> maritalStatusPreferenceList = new List<MaritalStatusPreference>();
				while (dataReader.Read())
				{
					MaritalStatusPreference maritalStatusPreference = MakeMaritalStatusPreference(dataReader);
					maritalStatusPreferenceList.Add(maritalStatusPreference);
				}

				return maritalStatusPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the MaritalStatusPreference table by a foreign key.
		/// </summary>
		public  List<MaritalStatusPreference> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MaritalStatusPreferenceSelectAllByProfileID", parameters))
			{
				List<MaritalStatusPreference> maritalStatusPreferenceList = new List<MaritalStatusPreference>();
				while (dataReader.Read())
				{
					MaritalStatusPreference maritalStatusPreference = MakeMaritalStatusPreference(dataReader);
					maritalStatusPreferenceList.Add(maritalStatusPreference);
				}

				return maritalStatusPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the MaritalStatusPreference table by a foreign key.
		/// </summary>
		public  List<MaritalStatusPreference> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MaritalStatusPreferenceSelectAllByTenantID", parameters))
			{
				List<MaritalStatusPreference> maritalStatusPreferenceList = new List<MaritalStatusPreference>();
				while (dataReader.Read())
				{
					MaritalStatusPreference maritalStatusPreference = MakeMaritalStatusPreference(dataReader);
					maritalStatusPreferenceList.Add(maritalStatusPreference);
				}

				return maritalStatusPreferenceList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MaritalStatusPreference class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MaritalStatusPreference MakeMaritalStatusPreference(SqlDataReader dataReader)
		{
			MaritalStatusPreference maritalStatusPreference = new MaritalStatusPreference();
			maritalStatusPreference.PreferenceID = SqlClientUtility.GetInt32(dataReader, "PreferenceID", 0);
			maritalStatusPreference.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			maritalStatusPreference.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			maritalStatusPreference.MartialStatusID = SqlClientUtility.GetInt32(dataReader, "MartialStatusID", 0);

			return maritalStatusPreference;
		}

		#endregion
	}
}
